-
A navigation service coordinates various nonvisual components that track the user as they navigate along a predetermined route. You use
MapboxNavigationService
, which conforms to this protocol, either as part ofNavigationViewController
or by itself as part of a custom user interface. A navigation service calls methods on itsdelegate
, which conforms to theNavigationServiceDelegate
protocol, whenever significant events or decision points occur along the route.A navigation service controls a
NavigationLocationManager
for determining the user’s location, aRouter
that tracks the user’s progress along the route, aMapboxRoutingProvider
service for calculating new routes (only used when rerouting), and aNavigationEventsManager
for sending telemetry events related to navigation or user feedback.NavigationViewController
comes with aMapboxNavigationService
by default. You may override it to customize theMapboxRoutingProvider
‘s source service or simulation mode. After creating the navigation service, pass it intoNavigationOptions(styles:navigationService:voiceController:topBanner:bottomBanner:)
, then pass that object intoNavigationViewController(for:options:)
.If you use a navigation service by itself, outside of
See moreNavigationViewController
, callstart()
when the user is ready to begin navigating along the route.Declaration
Swift
public protocol NavigationService : CLLocationManagerDelegate, ActiveNavigationEventsManagerDataSource, RouterDataSource
-
A navigation service delegate interacts with one or more
NavigationService
instances (such asMapboxNavigationService
objects) during turn-by-turn navigation. This protocol is the main way that your application can synchronize its state with the SDK’s location-related functionality. Each of the protocol’s methods is optional.As the user progresses along a route, a navigation service informs its delegate about significant events as they occur, and the delegate has opportunities to influence the route and its presentation. For example, when the navigation service reports that the user has arrived at the destination, your delegate implementation could present information about the destination. It could also customize individual visual or spoken instructions along the route by returning modified instruction objects.
Assign a
NavigationServiceDelegate
instance to theNavigationService.delegate
property of the navigation service before you start the service.The
RouterDelegate
protocol defines corresponding methods so that aRouter
instance can interact with an object that is both a router delegate and a navigation service, which in turn interacts with a navigation service delegate. Additionally, several location-related methods in this protocol have corresponding methods in theNavigationViewControllerDelegate
protocol, which can be convenient if you are using the navigation service in conjunction with aNavigationViewController
. Normally, you would either implement methods inNavigationServiceDelegate
orNavigationViewControllerDelegate
but notRouterDelegate
.Seealso
NavigationViewControllerDelegateSeealso
RouterDelegateDeclaration
Swift
public protocol NavigationServiceDelegate : AnyObject, UnimplementedLogging
-
A concrete implementation of the
NavigationService
protocol.NavigationViewController
comes with aMapboxNavigationService
by default. You may override it to customize theDirections
service or simulation mode. After creating the navigation service, pass it intoNavigationOptions(styles:navigationService:voiceController:topBanner:bottomBanner:)
, then pass that object intoNavigationViewController(for:options:)
.If you use a navigation service by itself, outside of
See moreNavigationViewController
, callstart()
when the user is ready to begin navigating along the route.Declaration
Swift
public class MapboxNavigationService : NSObject, NavigationService
extension MapboxNavigationService: CLLocationManagerDelegate
extension MapboxNavigationService: RouterDelegate
extension MapboxNavigationService: ReplayManagerHistoryEventsListener
-
A class conforming to the
Router
protocol tracks the user’s progress as they travel along a predetermined route. It calls methods on itsdelegate
, which conforms to theRouterDelegate
protocol, whenever significant events or decision points occur along the route. Despite its name, this protocol does not define the interface of a routing engine.There are two concrete implementations of the
See moreRouter
protocol.RouteController
, the default implementation, is capable of client-side routing and depends on the Mapbox Navigation Native framework.LegacyRouteController
is an alternative implementation that does not have this dependency but must be used in conjunction with the Mapbox Directions API over a network connection.Declaration
Swift
public protocol Router : CLLocationManagerDelegate
-
A router data source, also known as a location manager, supplies location data to a
See moreRouter
instance. For example, aMapboxNavigationService
supplies location data to aRouteController
orLegacyRouteController
.Declaration
Swift
public protocol RouterDataSource : AnyObject
-
A
RouteController
tracks the user’s progress along a route, posting notifications as the user reaches significant points along the route. On every location update, the route controller evaluates the user’s location, determining whether the user remains on the route. If not, the route controller calculates a new route.RouteController
is responsible for the core navigation logic whereasNavigationViewController
is responsible for displaying a default drop-in navigation UI.Important
Creating an instance of this type will start an Active Guidance session. The trip session is stopped when the instance is deallocated. From more info read the Pricing Guide.Precondition
There should be only oneRouteController
alive to any given time.Declaration
Swift
open class RouteController : NSObject
extension RouteController: HistoryRecording
extension RouteController: Router
-
A router delegate interacts with one or more
Router
instances, such asRouteController
objects, during turn-by-turn navigation. This protocol is similar toNavigationServiceDelegate
, which is the main way that your application can synchronize its state with the SDK’s location-related functionality. Normally, you should not need to make a class conform to theRouterDelegate
protocol or call any of its methods directly, but you would need to call this protocol’s methods if you implement a customRouter
class.MapboxNavigationService
is the only concrete implementation of a router delegate. Implement theNavigationServiceDelegate
protocol instead to be notified when various significant events occur along the route tracked by aNavigationService
.Seealso
MapboxNavigationServiceSeealso
NavigationServiceDelegateDeclaration
Swift
public protocol RouterDelegate : AnyObject, UnimplementedLogging
-
See moreRouteProgress
stores the user’s progress along a route.Declaration
Swift
open class RouteProgress : Codable
-
See moreRouteLegProgress
stores the user’s progress along a route leg.Declaration
Swift
open class RouteLegProgress : Codable
-
See moreRouteStepProgress
stores the user’s progress along a route step.Declaration
Swift
open class RouteStepProgress : Codable
-
Declaration
Swift
extension CongestionLevel
-
Declaration
Swift
extension VisualInstruction
-
The
See moreVisualInstructionDelegate
protocol defines a method that allows an object to customize presented visual instructions.Declaration
Swift
public protocol VisualInstructionDelegate : AnyObject, UnimplementedLogging
-
The
See moreNavigationEventsManager
is responsible for being the liaison between MapboxCoreNavigation and the Mapbox telemetry.Declaration
Swift
open class NavigationEventsManager
-
The
See moreActiveNavigationEventsManagerDataSource
protocol declares values required for recording route following events.Declaration
Swift
public protocol ActiveNavigationEventsManagerDataSource : AnyObject
-
A data source that declares values required for recording passive location events.
See moreDeclaration
Swift
public protocol PassiveNavigationEventsManagerDataSource : AnyObject
-
See moreNavigationLocationManager
is the base location manager which handles permissions and background modes.Declaration
Swift
open class NavigationLocationManager : CLLocationManager
extension NavigationLocationManager: RouterDataSource
-
See moreReplayLocationManager
replays an array of locations exactly as they were recorded with the single exception of the location’s timestamp which will be adjusted by interval between locations.Declaration
Swift
open class ReplayLocationManager : NavigationLocationManager
-
The
SimulatedLocationManager
class simulates location updates along a given route.The route will be replaced upon a
RouteControllerDidReroute
notification.The manager calls delegate methods on a background thread.
See moreDeclaration
Swift
open class SimulatedLocationManager : NavigationLocationManager
-
A
NavigationRouteOptions
object specifies turn-by-turn-optimized criteria for results returned by the Mapbox Directions API.NavigationRouteOptions
is a subclass ofRouteOptions
that has been optimized for navigation. Pass an instance of this class into theDirections.calculate(_:completionHandler:)
method.This class implements the
NSCopying
protocol by round-tripping the object throughJSONEncoder
andJSONDecoder
. If you subclassNavigationRouteOptions
, make sure any properties you add are accounted for inDecodable(from:)
andEncodable.encode(to:)
. If your subclass contains any customizations that cannot be represented in JSON, make sure the subclass overridesNSCopying.copy(with:)
to persist those customizations.
See moreNavigationRouteOptions
is designed to be used with theDirections
andNavigationDirections
classes for specifying routing criteria. To customize the user experience in aNavigationViewController
, use theNavigationOptions
class.Declaration
Swift
open class NavigationRouteOptions : RouteOptions, OptimizedForNavigation
-
Declaration
Swift
extension DirectionsOptions
-
A
NavigationMatchOptions
object specifies turn-by-turn-optimized criteria for results returned by the Mapbox Map Matching API.NavigationMatchOptions
is a subclass ofMatchOptions
that has been optimized for navigation. Pass an instance of this class into theDirections.calculateRoutes(matching:completionHandler:).
method.Note: it is very important you specify the
See morewaypoints
for the route. Usually the only two values for thisIndexSet
will be 0 and the length of the coordinates. Otherwise, all coordinates passed through will be considered waypoints.Declaration
Swift
open class NavigationMatchOptions : MatchOptions, OptimizedForNavigation
-
The simulation mode type. Used for setting the simulation mode of the navigation service.
See moreDeclaration
Swift
public enum SimulationMode : Int
-
The simulation intent type. Used for describing the intent to start simulation of the navigation service.
See moreDeclaration
Swift
public enum SimulationIntent : Int
-
The simulation state type. Used for notifying users of the change of navigation service simulation status.
See moreDeclaration
Swift
public enum SimulationState : Int
-
An object that notifies its delegate when the user’s location changes, minimizing the noise that normally accompanies location updates from a
CLLocationManager
object.Unlike
Router
classes such asRouteController
andLegacyRouteController
, this class operates without a predefined route, matching the user’s location to the road network at large. You can use a passive location manager to determine a starting point for a route that you calculate using theDirections.calculate(_:completionHandler:)
method. If the user happens to be moving while you calculate the route, the passive location manager makes it less likely that the route will begin with a short segment on a side road or driveway and a confusing instruction to turn onto the current road.To find out when the user’s location changes, implement the
PassiveLocationManagerDelegate
protocol, or observeNotification.Name.passiveLocationManagerDidUpdate
notifications for more detailed information.Important
Creating an instance of this class will start a free-driving session. If the application goes into the background or you temporarily stop needing location updates for any other reason, temporarily pause the trip session using thePassiveLocationManager.pauseTripSession()
method to avoid unnecessary costs. The trip session also stops when the instance is deinitialized. For more information, see the “Pricing” guide.Declaration
Swift
open class PassiveLocationManager : NSObject
extension PassiveLocationManager: HistoryRecording
extension PassiveLocationManager: CLLocationManagerDelegate
extension PassiveLocationManager: PassiveNavigationEventsManagerDataSource
-
A delegate of a
See morePassiveLocationManager
object implements methods that the location manager calls as the user’s location changes.Declaration
Swift
public protocol PassiveLocationManagerDelegate : AnyObject